$(document).ready(function () {
    // 从localStorage中获取教师姓名
    var teacherName = localStorage.getItem('name');
    if (!teacherName) {
        alert('teacher name not found in localStorage');
        return;
    }
    // 向后端发送请求获取教师数据
    $.ajax({
        url: '/webapi/teacher/searchByTeacherName',
        method: 'GET',
        data: {
            teacherName: teacherName
        }
    }).done(function (data) {
        if (data && data.rows && data.rows.length > 0) {
            var teacher = data.rows[0]; // 假设返回的是一个教师列表，取第一个教师数据
            var teacherNo = teacher.teacherNo;
            // 初始化表格
            $('#selectTb').bootstrapTable({
                method: 'GET',
                url: '/webapi/select/selectionTeacher', // 初始加载地址，假设用于加载所有选课数据的接口
                striped: true,
                cache: false,
                pagination: true,
                sortable: false,
                sidePagination: "server", // 后端分页
                pageNumber: 1,
                pageSize: 3,
                pageList: [3, 6, 10, 20, 100],
                queryParams: function (params) {
                    return {
                        teacherNo: teacherNo, // 使用学号作为查询参数
                        pageSize: params.limit,
                        pageNum: params.offset / params.limit + 1
                    };
                },
                columns: [{
                    checkbox: true,
                }, {
                    field: 'id',
                    title: '选课ID'
                }, {
                    field: 'studentNo',
                    title: '学生学号'
                }, {
                    field: 'teacherNo',
                    title: '教师工号'
                }, {
                    field: 'cno',
                    title: '课程号'
                }]
            });
            // 点击按钮刷新表格
            $('#refreshBtn').click(function () {
                $('#selectTb').bootstrapTable('refresh');
            });
        }
    });
});